//
//  ZBAlert.m
//  ZBDay
//
//  Created by xzb on 2018/2/28.
//  Copyright © 2018年 xzb. All rights reserved.
//

#import "ZBAlert.h"
#import "MMAlertView.h"

@implementation ZBAlert

+ (void)alertWithTitle:(NSString *)title detail:(NSString *)detail items:(NSArray*)items
{
    MMAlertView *alertView = [[MMAlertView alloc] initWithTitle:title detail:detail items:items];
    [alertView show];
}

+ (void)alertWithMessage:(NSString *)message
{
    NSArray *items =  @[MMItemMake(@"完成", MMItemTypeHighlight,nil)];
    [ZBAlert alertWithTitle:@"提示" detail:message items:items];
}

+ (void)alertWithMessage:(NSString *)message items:(NSArray <NSString *> *)items completion:(ZBAlertHandleBlcok)completion
{
    [self alertWithTitle:@"提示" detail:message items:[self itemsForStrItems:items completion:completion]];
}

+ (NSMutableArray *)itemsForStrItems:(NSArray <NSString *> *)items completion:(ZBAlertHandleBlcok)completion
{
    NSMutableArray *mmItems = [[NSMutableArray alloc] initWithCapacity:items.count];
    for (NSString *title in items) {
        if ([title hasPrefix:@"H_"]) {
            [mmItems addObject:MMItemMake([title substringFromIndex:2], MMItemTypeHighlight,completion)];
        } else if ([title hasPrefix:@"D_"]) {
            [mmItems addObject:MMItemMake([title substringFromIndex:2], MMItemTypeDisabled,completion)];
        } else {
            [mmItems addObject:MMItemMake(title, MMItemTypeNormal,completion)];
        }
    }
    return mmItems;
}

+ (void)inputAlertWithMessage:(NSString *)message placeholder:(NSString *)placeholder complete:(ZBInputAlertHandleBlock)complete
{
    MMAlertView *alertView = [[MMAlertView alloc] initWithInputTitle:@"提示" detail:message placeholder:placeholder handler:complete];
//    UITextField *textField = [alertView valueForKey:@"inputView"];
    [alertView show];
}

@end
